package com.zhyonk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhyonk.domain.School;
import com.zhyonk.mapper.SchoolMapper;
import com.zhyonk.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cbl
 * @description com.zhyonk.service.impl
 * @date 2020/7/10
 */
@Service
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Override
    public School randomSchool() {
        QueryWrapper<School> wrapper = new QueryWrapper<School>();
        wrapper.last("where sc_id >= ((SELECT MAX(sc_id) FROM school)-(SELECT MIN(sc_id) FROM school)) * RAND() + (SELECT MIN(sc_id) FROM school)  LIMIT 1");
        String sqlSelect = wrapper.getSqlSelect();
        System.out.println(sqlSelect);
        return schoolMapper.selectOne(wrapper);

    }
}
